home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / regkey10.zip / USEKEY.C < prev   
C/C++ Source or Header  |  1992-07-19  |  3KB  |  56 lines

  1. /* Sample program which uses the registration key system. This program's
  2.  * security code is 24805 - I would suggest that you change this value
  3.  * use in any programs you have written. When compiled, this program must
  4.  * be linked with the BP?.LIB file. For more information on compiling
  5.  * programs using the registration key system, please see the accompanying
  6.  * documentation, in the file REGKEY.DOC. This program reads the
  7.  * registration information from the file REGISTER.KEY. The program expects
  8.  * to find the registered user's name on the first line of this file, and
  9.  * the user's registration key on the second line of this file.
  10.  */
  11.  
  12.  
  13. #include "bp.h"           /* Include the registration key system header file */
  14.  
  15. #include <stdio.h>                                   /* Other C header files */
  16. #include <string.h>
  17.  
  18. char registered=0;                              /* 1 if registered, 0 if not */
  19. char registered_name[201];                        /* Name of registered user */
  20.  
  21. main()                                              /* Main program function */
  22.    {
  23.    FILE *fp;                           /* File pointer for REGISTER.KEY file */
  24.    unsigned long supplied_key;                       /* Key supplied by user */
  25.    unsigned long correct_key;                    /* Correct registration key */
  26.  
  27.    if((fp=fopen("REGISTER.KEY","r"))!=NULL)              /* Try to open file */
  28.       {                                                     /* If successful */
  29.       fgets(registered_name,200,fp);                  /* read name from file */
  30.       if(registered_name[strlen(registered_name)-1]=='\n')
  31.          registered_name[strlen(registered_name)-1]='\0';
  32.  
  33.       fscanf(fp,"%lu",&supplied_key);                  /* read key from file */
  34.  
  35.       fclose(fp);                                              /* Close file */
  36.  
  37.       correct_key=bp(registered_name,24805);        /* Calculate correct key */
  38.  
  39.       if(correct_key==supplied_key)       /* Compare correct & supplied keys */
  40.          {                                          /* If they are identical */
  41.          registered=1;           /* Then switch program into registered mode */
  42.          }
  43.       }
  44.  
  45.    if(registered==1)                                   /* If registered mode */
  46.       {                                  /* Display registration information */
  47.       printf("This program is registered to: %s\n",registered_name);
  48.       }
  49.    else if(registered==0)                       /* If not in registered mode */
  50.       {                                  /* Display unregistered information */
  51.       printf("This program is UNREGISTERED!!!\n");
  52.       }
  53.    }
  54.  
  55.  
  56.